package com.buba.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.buba.service.InsuranceFileService;
import common.R;
import entity.salary.InsuranceFile;
import entity.salary.dto.AccountDto;
import entity.salary.vo.selAccSocialAccumVo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author beisheng
 * @since 2023-03-20
 */
@RestController
@RequestMapping("/insurance-file")
public class InsuranceFileController {

    @Resource
    private InsuranceFileService insuranceFileService;

    /* *
     * @Author: beisheng
     * @Descriprion: 查询个人参保档案
     * @Date: 2023/3/21 14:42
     * @Return: common.R
     * @Param: [insuranceId]
     */

    @GetMapping("/selInsuranceFile/{insuranceId}")
    public R selInsuranceFile(@PathVariable("insuranceId") Integer insuranceId){
        return R.success(insuranceFileService.selInsuranceFile(insuranceId));
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 进行增员调整,如果是调整方案，那么进行添加调整记录
     * @Date: 2023/3/20 19:32
     * @Return: common.R
     * @Param: [saveAccountDto]
     */

    @PostMapping("/saveAccount")
    public R saveAccount(@RequestBody AccountDto saveAccountDto){
        insuranceFileService.saveAccount(saveAccountDto);
        return R.success();
    }
    /**
     * 功能描述: 新增或更新
     *
     * @param insuranceFile
     * @return
     * @throws
     * @Author: beisheng
     */
    @PostMapping("/save")
    public R save(@RequestBody InsuranceFile insuranceFile) {
        insuranceFileService.saveOrUpdate(insuranceFile);
        return R.success();
    }

    /**
     * 功能描述: 删除
     *
     * @param id
     * @return
     * @throws
     * @Author: beisheng
     */
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable Integer id) {
        insuranceFileService.removeById(id);
        return R.success();
    }

    /**
     * 功能描述: 批量删除
     *
     * @param ids
     * @return
     * @throws
     * @Author: beisheng
     */
    @PostMapping("/deleteBatch")
    public R deleteBatch(@RequestBody List<Integer> ids) {
        insuranceFileService.removeByIds(ids);
        return R.success();
    }

    /**
     * 功能描述: 全查
     *
     * @param
     * @return
     * @throws
     * @Author: beisheng
     */
    @GetMapping("/findAll")
    public R findAll() {
        return R.success(insuranceFileService.list());
    }

    /**
     * 功能描述: 单查
     *
     * @param id
     * @return
     * @throws
     * @Author: beisheng
     */
    @GetMapping("/findOne/{id}")
    public R findOne(@PathVariable Integer id) {
        return R.success(insuranceFileService.getById(id));
    }

    /**
     * 功能描述: 分页查询
     *
     * @param pageNum
     * @param pageSize
     * @return
     * @throws
     * @Author: beisheng
     * @Date:   2022/7/28 19:15
     */
    @GetMapping("/findPage")
    public R findPage(@RequestParam Integer pageNum,
                                 @RequestParam Integer pageSize) {
        QueryWrapper<InsuranceFile> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return R.success(insuranceFileService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 根据档案ID查询社保公积金基本信息
     * @Date: 2023/3/21 16:25
     * @Return: common.R
     * @Param: [insurId]
     */

    @GetMapping("/selSocialAndAccum")
    public selAccSocialAccumVo selSocialAndAccum(@RequestBody Integer insurId){
        return insuranceFileService.selSocialAndAccum(insurId);
    }
}
